const {API_URL, MOCK_URL} = require(`./../config/${ENV}.json`);

import nattyFetch from 'natty-fetch';

nattyFetch.setGlobal({
  // 配置整个项目所有接口的参数中都包含`__token`字段
});

const context = nattyFetch.context({
  urlPrefix: API_URL,
  mockUrlPrefix: MOCK_URL,
  mock: false,
  method: 'POST',
  postDataFormat: 'JSON',
  overrideSelfConcurrent: true,
  header: {
    'Content-Type': 'application/json;charset=utf-8'
  },
  data: {
    page: "1", // 表示请求页码的参数名称
    size: "10", // 表示请求行数的参数名称
    sort: "createdTime,DESC", // 表示用于排序的列名的参数名称 例  coding,DESC
  },
  timeout: 45000,
  fit: function (response) {
    console.log(response);
    let ret = {
      success: response.success
    };
    if (ret.success) {
      ret.content = response.data;
    } else {
      ret.error = {
        message: response.msg
      }
    }
    return ret;
  }
});


context.create({


  'message.list': {
    mock: false,
    method: 'GET',
    url: 'dingtalk/nmessage/list',
    fit: function (response) {
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },


  //获取内部通知数量
  'message.count': {
    mock: false,
    method: 'GET',
    url: 'dingtalk/nmessage/count',
    fit: function (response) {
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取在手工程数量
  'eng.count': {
    mock: false,
    method: 'GET',
    url: 'jd/eng/count',
    fit: function (response) {
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取钉钉配置
  'config.get': {
    url: 'dingtalk/config/get',
    method: 'POST',
    plugins: [
      nattyFetch.plugin.loop
    ],
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取盯盘控件
  'dp.get': {
    method: 'POST',
    url: 'dingtalk/pan/get',
  },

  //发送OA消息
  'message.oa.send': {
    method: 'POST',
    url: 'dingtalk/message/send/oa',
  },

  //获取任务步骤
  'jdrwmx.db.get.steps': {
    mock: false,
    method: 'GET',
    url: 'jd/txrw/step/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取任务明细
  'jdrwmx.db.get.mx': {
    mock: false,
    method: 'GET',
    url: 'jd/txrw/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取任务列表
  'jdrwmx.db.get.up': {
    mock: false,
    method: 'GET',
    url: 'jd/txrw/dsh/page',

    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
  //操作任务
  'jdrwmx.db.send': {
    mock: false,
    method: 'GET',
    url: 'jd/txrw/send',
    ignoreSelfConcurrent: true,
    fit: function (response) {
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
  //获取待办事项数量
  'jdrwmx.db.get.count': {
    mock: false,
    method: 'GET',
    url: 'jd/txrw/count/get',

    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //查询工程列表
  'eng.get.search': {
    mock: false,
    method: 'GET',
    url: 'jd/eng/page',
    fit: function (response) {
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },


  //获取钉钉用户信息
  'user.get': {
    mock: false,
    url: 'dingtalk/userinfo/get',
    storage: {
      type: 'localStorage',  // 缓存方式, 默认为'localStorage'
      key: 'sskj-dingtalk-user',     // !!! 唯一必选的参数, 用于内部存储 !!!
      tag: 'v1.0.0.0',          // 缓存的标记, 用于判断是否有效
      duration: 1000 * 60 * 100,      // 缓存的有效期长, 以毫秒数指定
    },

    fit: function (response) {
      console.log(response);
      console.log('获取钉钉用户信息');

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
        console.log('获取钉钉用户信息_ok');
      } else {
        console.log('获取钉钉用户信息_error');
        ret.error = {
          message: response.msg
        };
      }
      return ret;
    }
  },


  //查询记录列表
  'jilu.get.search': {
    mock: false,
    method: 'GET',
    url: 'jd/jdjl/page',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data.content;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },


  //获取质量验收记录
  'zlysjl.get': {
    mock: false,
    method: 'GET',
    url: 'jd/zlysjl/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //删除质量验收记录
  'zlysjl.del': {
    mock: false,
    method: 'GET',
    url: 'jd/zlysjl/del',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //上传质量验收记录
  'zlysjl.up': {
    mock: false,
    method: 'GET',
    url: 'jd/zlysjl/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //保存质量验收记录
  'zlysjl.save': {
    method: 'POST',
    mock: false,
    postDataFormat: 'JSON',
    url: 'jd/zlysjl/save',
    ignoreSelfConcurrent: true,

    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取质量巡查记录
  'zlxcjl.get': {
    mock: false,
    method: 'GET',
    url: 'jd/zlxcjl/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //删除质量检查记录
  'zlxcjl.del': {
    mock: false,
    method: 'GET',
    url: 'jd/zlxcjl/del',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //上传质量检查记录
  'zlxcjl.up': {
    mock: false,
    method: 'GET',
    url: 'jd/zlxcjl/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
  //保存质量检查记录
  'zlxcjl.save': {
    method: 'POST',
    mock: false,
    postDataFormat: 'JSON',
    url: 'jd/zlxcjl/save',
    ignoreSelfConcurrent: true,

    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取安全巡查记录
  'aqxcjl.get': {
    mock: false,
    method: 'GET',
    url: 'jd/aqxcjl/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //删除安全检查记录
  'aqxcjl.del': {
    mock: false,
    method: 'GET',
    url: 'jd/aqxcjl/del',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //保存安全检查记录
  'aqxcjl.save': {
    method: 'POST',
    mock: false,
    postDataFormat: 'JSON',
    url: 'jd/aqxcjl/save',
    ignoreSelfConcurrent: true,

    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //上传安全检查记录
  'aqxcjl.up': {
    mock: false,
    method: 'GET',
    url: 'jd/aqxcjl/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取质量整改通知书
  'zlzgtzs.get': {
    mock: false,
    method: 'GET',
    url: 'jd/zlzgtzs/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //上传质量问题整改通知书
  'zlzgtzs.up': {
    mock: false,
    method: 'GET',
    url: 'jd/zlzgtzs/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      //alert( JSON.stringify(response));

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
  //保存质量整改通知书
  'zlzgtzs.save': {
    method: 'POST',
    mock: false,
    postDataFormat: 'JSON',
    url: 'jd/zlzgtzs/save',
    ignoreSelfConcurrent: true,

    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
  //删除质量整改通知书
  'zlzgtzs.del': {
    mock: false,
    method: 'GET',
    url: 'jd/zlzgtzs/del',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },


  //获取安全整改通知书
  'aqzgtzs.get': {
    mock: false,
    method: 'GET',
    url: 'jd/aqzgtzs/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //上传安全问题整改通知书
  'aqzgtzs.up': {
    mock: false,
    method: 'GET',
    url: 'jd/aqzgtzs/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      //alert( JSON.stringify(response));

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
  //保存安全整改通知书
  'aqzgtzs.save': {
    method: 'POST',
    mock: false,
    postDataFormat: 'JSON',
    url: 'jd/aqzgtzs/save',
    ignoreSelfConcurrent: true,

    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
  //删除安全整改通知书
  'aqzgtzs.del': {
    mock: false,
    method: 'GET',
    url: 'jd/aqzgtzs/del',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },


  //上传安全问题整改通知书
  'aqzgtzs.up': {
    mock: false,
    method: 'GET',
    url: 'jd/aqzgtzs/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      //alert( JSON.stringify(response));

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //保存质量局部暂停施工通知书
  'zljbtg.save': {
    method: 'POST',
    mock: false,
    postDataFormat: 'JSON',
    url: 'jd/zljbtgtzs/save',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取质量局部停工通知书
  'zljbtg.get': {
    mock: false,
    method: 'GET',
    url: 'jd/zljbtgtzs/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //删除局部停工通知书
  'zljbtg.del': {
    mock: false,
    method: 'GET',
    url: 'jd/zljbtgtzs/del',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //上传质量局部停工通知书
  'zljbtg.up': {
    mock: false,
    method: 'GET',
    url: 'jd/zljbtgtzs/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },


  //保存安全局部暂停施工通知书
  'aqjbtg.save': {
    method: 'POST',
    mock: false,
    postDataFormat: 'JSON',
    url: 'jd/aqjbtgtzs/save',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取安全局部停工通知书
  'aqjbtg.get': {
    mock: false,
    method: 'GET',
    url: 'jd/aqjbtgtzs/get',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //删除安全局部停工通知书
  'aqjbtg.del': {
    mock: false,
    method: 'GET',
    url: 'jd/aqjbtgtzs/del',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //上传安全局部停工通知书
  'aqjbtg.up': {
    mock: false,
    method: 'GET',
    url: 'jd/aqjbtgtzs/upload',
    ignoreSelfConcurrent: true,
    fit: function (response) {

      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },
});

module.exports = context.api;
